package me.miencraft.plugin.superlobby.command;

import me.miencraft.plugin.superlobby.util.VisiblePlayer;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;

import java.util.Arrays;
import java.util.List;

/**
 * @author langle__
 * @version 1.0
 */
public class VisibleCommand implements TabExecutor {

    @Override
    public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
        if (!(sender instanceof Player)) {
            sender.sendMessage("只有玩家才能执行此命令");
            return false;
        }
        Player player = (Player) sender;
        boolean visible = VisiblePlayer.isVisible(player);
        if (args.length == 0) {
            VisiblePlayer.toggleVisibility(player);
            player.sendMessage("玩家隐藏: " + (!visible ? "§a启用" : "§c禁用"));
            return true;
        }
        String cmd = args[0].toLowerCase();
        switch (cmd) {
            case "on":
                VisiblePlayer.enableVisibility(player);
                player.sendMessage("玩家隐藏: §a启用");
                break;
            case "off":
                VisiblePlayer.disableVisibility(player);
                player.sendMessage("玩家隐藏: §c禁用");
                break;
            case "toggle":
                VisiblePlayer.toggleVisibility(player);
                player.sendMessage("玩家隐藏: " + (!visible ? "§a启用" : "§c禁用"));
                break;
        }
        return true;
    }

    @Override
    public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, @NotNull String[] args) {
        return Arrays.asList("on", "off", "toggle");
    }

}
